package com.sz.business.servlet;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.servlet.ModelAndView;
import com.sz.business.bmo.IBusinessBMO;

import org.springframework.web.servlet.mvc.Controller;

public class UpdateBusiness extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
	protected final Log logger = LogFactory.getLog(getClass());
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request, response);
	}
	
	@SuppressWarnings("unchecked")
	public void doPost(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException {
		try {
			
			String rtn_type = request.getParameter("return_type");
			String path = request.getContextPath(); 
			
			ServletContext servletContext = request.getSession().getServletContext();        
			ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
			
			IBusinessBMO businessBMO = (IBusinessBMO) context.getBean("BusinessBMO");

			Map mapBusiness = new HashMap();
			
			String Business_ID              = request.getParameter("Business_ID");
			String Business_Region_ID       = request.getParameter("business_region_id");
			String Business_Group_ID        = request.getParameter("business_group_id");
			String Business_InfoSource      = request.getParameter("Business_InfoSource");
			String Business_CheckStatus     = request.getParameter("Business_CheckStatus");
			String Business_WorkStatus      = request.getParameter("Business_WorkStatus");
			String Business_PreorderFlag    = request.getParameter("Business_PreorderFlag");
			String Business_PublishState    = request.getParameter("Business_PublishState");
			String Business_RedFlag         = request.getParameter("Business_RedFlag");
			String Business_X               = request.getParameter("Business_X");
			String Business_Y               = request.getParameter("Business_Y");
			String Business_Name            = request.getParameter("Business_Name");
			String Business_NameEnglish     = request.getParameter("Business_NameEnglish");
			String Business_Alias           = request.getParameter("Business_Alias");
			String Business_LoginName       = request.getParameter("Business_LoginName");
			String Business_Tel1            = request.getParameter("Business_Tel1");
			String Business_Adress          = request.getParameter("Business_Adress");
			String Business_PostCode        = request.getParameter("Business_PostCode");
			String Business_CrossRoad       = request.getParameter("Business_CrossRoad");
			String Business_LandMark        = request.getParameter("Business_LandMark");
			String Business_Traffic         = request.getParameter("Business_Traffic");
			String Business_Descript        = request.getParameter("Business_Descript");
			String Business_Email           = request.getParameter("Business_Email");
			String Business_NetAddress      = request.getParameter("Business_NetAddress");
			String Business_Fax             = request.getParameter("Business_Fax");
			String Business_MainUser        = request.getParameter("Business_MainUser");
			String Business_MainUser_Tel    = request.getParameter("Business_MainUser_Tel");
			String Main_Serial              = request.getParameter("course_serial_id");
			String Business_SpecialCourse   = request.getParameter("Business_SpecialCourse");
			String Business_Flavor          = request.getParameter("Business_Flavor");
			String Business_AvgFee          = request.getParameter("Business_AvgFee");
			String Business_LowFee          = request.getParameter("Business_LowFee");
			String Business_Discount        = request.getParameter("Business_Discount");
			String Business_RoomFlag        = request.getParameter("Business_RoomFlag");
			String Business_PreorderDescrip = request.getParameter("Business_PreorderDescrip");
			String Business_Reserve         = request.getParameter("Business_Reserve");
			String Business_WorkTime        = request.getParameter("Business_WorkTime");
			String Business_RoomNum         = request.getParameter("Business_RoomNum");
			String Business_RoomDescrip     = request.getParameter("Business_RoomDescrip");
			String Business_Devices         = request.getParameter("Business_Devices");
			String Business_CreditCardFlag  = request.getParameter("Business_CreditCardFlag");
			String Business_CousumeCardFlag = request.getParameter("Business_CousumeCardFlag");
			String Business_CardTypeInfo    = request.getParameter("Business_CardTypeInfo");
			String Business_ServiceDescrip  = request.getParameter("Business_ServiceDescrip");
			String Business_ParkDescrip     = request.getParameter("Business_ParkDescrip");
			String Business_OutDescrip      = request.getParameter("Business_OutDescrip");
			String Business_Area            = request.getParameter("Business_Area");
			String Business_Environment     = request.getParameter("Business_Environment");
			String Business_KeyWords        = request.getParameter("Business_KeyWords");
			String Business_CommentText     = request.getParameter("Business_CommentText");
			String Business_DepositDescrip  = request.getParameter("Business_DepositDescrip");
			String Business_CheckOrderMode  = request.getParameter("Business_CheckOrderMode");
			String Business_CheckContact    = request.getParameter("Business_CheckContact");
			String Business_CheckTel        = request.getParameter("Business_CheckTel");	
			String Modify_Manager           = request.getSession().getAttribute("username").toString();
			
			
			mapBusiness.put("REGION_ID"               , Business_Region_ID      );
			mapBusiness.put("GROUP_ID"                , Business_Group_ID       );
			mapBusiness.put("INFO_SOURCE"             , Business_InfoSource     );
			mapBusiness.put("CHECK_STATUS"            , Business_CheckStatus    );
			mapBusiness.put("WORK_STATUS"             , Business_WorkStatus     );
			mapBusiness.put("PREORDER_FLAG"           , Business_PreorderFlag   );
			mapBusiness.put("PUBLISH_STATE"           , Business_PublishState   );
			mapBusiness.put("RED_FLAG"                , Business_RedFlag        );
			mapBusiness.put("X"           			  , Business_X              );
			mapBusiness.put("Y"                       , Business_Y              );
			mapBusiness.put("NAME"                    , Business_Name           );
			mapBusiness.put("NAME_ENGLISH"            , Business_NameEnglish    );
			mapBusiness.put("ALIAS"                   , Business_Alias          );
			mapBusiness.put("LOGIN_NAME"              , Business_LoginName      );
			mapBusiness.put("TEL1"                    , Business_Tel1           );
			mapBusiness.put("ADDRESS"                 , Business_Adress         );
			mapBusiness.put("POST_CODE"               , Business_PostCode       );
			mapBusiness.put("CROSSROAD"               , Business_CrossRoad      );
			mapBusiness.put("LANDMARK"                , Business_LandMark       );
			mapBusiness.put("TRAFFIC"                 , Business_Traffic        );  
			mapBusiness.put("DESCRIPT"                , Business_Descript       );
			mapBusiness.put("EMAIL"                   , Business_Email          );
			mapBusiness.put("NET_ADDRESS"             , Business_NetAddress     );
			mapBusiness.put("FAX"                     , Business_Fax            );
			mapBusiness.put("MAIN_USER"               , Business_MainUser       );
			mapBusiness.put("MAIN_USER_TEL"           , Business_MainUser_Tel   );
			mapBusiness.put("MAIN_SERIAL"             , Main_Serial        );
			mapBusiness.put("SPECIAL_COURSE"          , Business_SpecialCourse  );
			mapBusiness.put("FLAVOUR"                 , Business_Flavor         );
			mapBusiness.put("AVG_FEE"                 , Business_AvgFee         );
			mapBusiness.put("LOW_FEE"                 , Business_LowFee         );
			mapBusiness.put("DISCOUNT"                , Business_Discount       );
			mapBusiness.put("ROOM_FLAG"               , Business_RoomFlag       );
			mapBusiness.put("PREORDER_DESCRIP"        , Business_PreorderDescrip);
			mapBusiness.put("RESERVE"                 , Business_Reserve        );
			mapBusiness.put("WORKTIME"                , Business_WorkTime       );
			mapBusiness.put("ROOM_NUM"                , Business_RoomNum        );
			mapBusiness.put("ROOM_DESCRIP"            , Business_RoomDescrip    );
			mapBusiness.put("DEVICES"                 , Business_Devices        );
			mapBusiness.put("CREDITCARD_FLAG"         , Business_CreditCardFlag );
			mapBusiness.put("CONSUMECARD_FLAG"        , Business_CousumeCardFlag);
			mapBusiness.put("CARD_TYPE_INFO"          , Business_CardTypeInfo   );
			mapBusiness.put("SERVICE_DESCRIP"         , Business_ServiceDescrip );
			mapBusiness.put("PARK_DESCRIP"            , Business_ParkDescrip    );
			mapBusiness.put("OUT_DESCRIP"             , Business_OutDescrip     );
			mapBusiness.put("AREA"                    , Business_Area           );
			mapBusiness.put("ENVIRONMENT"             , Business_Environment    );
			mapBusiness.put("KEYWORDS"                , Business_KeyWords       );
			mapBusiness.put("COMMENT_TEXT"            , Business_CommentText    );
			mapBusiness.put("DEPOSIT_DESCRIP"         , Business_DepositDescrip );
			mapBusiness.put("CHECK_ORDER_MODE"        , Business_CheckOrderMode );
			mapBusiness.put("CHECK_CONTACT"           , Business_CheckContact   );
			mapBusiness.put("CHECK_TEL"               , Business_CheckTel       );
			mapBusiness.put("INPUT_USER"              , Modify_Manager       );
			mapBusiness.put("BUSINESS_ID"             , Business_ID       );
			
			
			
			long r = businessBMO.updateBusiness(mapBusiness);
			logger.info(String.format("updateBusiness:%d", r));			

			if(r == 0) {
				if(rtn_type != null && rtn_type.compareToIgnoreCase("message")==0){
					response.setCharacterEncoding("utf-8");
					response.getWriter().print("成功！");
				} else {
					response.sendRedirect(path + "/page/success.jsp");
				}
			} else {
				if(rtn_type != null && rtn_type.compareToIgnoreCase("message")==0){
					response.setCharacterEncoding("utf-8");
					response.getWriter().print("失败");
				} else {
					response.sendRedirect(path + "/page/failure.jsp");

				}
			}
		} catch (Exception e) {
			logger.error(e.getMessage());
			throw new ServletException(e.getMessage());
		}
	}
}
